function PcCommon($, header,alertInfo) {
    var _Common_Config = {
        loadHistory: 1,// 1:保存,0:不保存,-1倒退
        footerDisp: 1,
        host: "",
        domain:"/",
        isDebug: false,
        // host:'http://localhost:8080',
        // isDebug:true,
        // domain:"https://www.acdelco.com.cn/",
        headerPos:{},
        headerDisp:1
    };

    $.fn.timeCaluactor = function (callback) {
        if ($(this).length > 0) {
            var array = $(this);
            setInterval(function () {
                $.each(array, function () {
                    callback.call(null, this);
                });
            }, 1000);
        }
    };


    return {
        init: function (options) {
            this._Options = $.extend({}, _Common_Config, options);
            if(MediaSize.isLessVersionIe()){
                this.initFontSetting();
            }
            //延迟加载头部信息
            if (this._Options.lazyHeader == true) {
                return;
            }

            this.header();
            this.footer();
            this.commonctrlsetting();
        },
        initFontSetting:function(){
            $(".wrapper").css({"font-size": MediaSize.widthFontsize() + "px"});
        },
        loadHistory: function () {

        },
        commonctrlsetting:function(){
            $("select").each(function(){
                var pos = $(this).width() - 4;
                $(this).css({"background-position-x":pos});
            });

        },
        header:function(){
            var _this = this;
            if (!_this._Options.headerDisp) {
                header.destory();
            } else {
                header.init(_this._Options.headerPos);
            }
        },
        footer:function(){
            var _this = this;
            $(window).on("scroll",function(){
               var sT = $(window).scrollTop();
               if(sT > 300){
                    $(".slide-top").fadeIn();
                    $(".slide-top").unbind("click").bind("click",function(){
                        $(window).scrollTop(0);
                    });
               }else{
                    $(".slide-top").unbind("click");
                    $(".slide-top").fadeOut();
               }
            });
        },
        closeFeed:function(){
            $('.feedback-mask').hide();
            $('.feedback').hide();
        },
        alertInfo:function(msg,type){
            var _this = this;
            alertInfo.init(msg,type)
        },
        // 日志
        logger: function (msg) {
            if (SYS_CONFIG.debug) {
                var str = "";
                if (msg instanceof Array) {
                    for (var key in msg) {
                        str += msg[key] + ","
                    }
                } else if (msg instanceof Object) {
                    for (var key in msg) {
                        str += key + ":" + msg[key] + ","
                    }
                } else {
                    str = msg;
                }
                console.log(str);
            }
        },
        utils: function () {
            var utils = utils || {
                formatDate:function (timeStamp) {
                    if(!timeStamp){
                        return "";
                    }
                    function zeroBu(n){
                        if(n<10){
                            return '0'+n;
                        }else{
                            return n
                        }
                    }
                    var time = new Date(timeStamp);
                    var y = zeroBu(time.getFullYear());//年
                    var m = zeroBu(time.getMonth() + 1);//月
                    var d = zeroBu(time.getDate());//日
                    var h =zeroBu( time.getHours());//时
                    var mm =zeroBu( time.getMinutes());//分
                    var s = zeroBu(time.getSeconds());//秒
                    var times=y+"-"+m+"-"+d+" "+h+":"+mm+":"+s;
                    return times;
                },
                formatDateYYmm:function (timeStamp) {
                    if(!timeStamp || timeStamp == "" || $.trim(timeStamp) == ""){
                        return "";
                    }

                    function zeroBu(n){
                        if(n<10){
                            return '0'+n;
                        }else{
                            return n
                        }
                    }
                    var time = new Date(timeStamp);
                    var y = zeroBu(time.getFullYear());//年
                    var m = zeroBu(time.getMonth() + 1);//月
                    var times=y+"-"+m;
                    return times;
                },
                // 是否为IE78
                browserIe: function () {
                    var explorer = navigator.userAgent;
                    //ie
                    if (explorer.indexOf("MSIE") >= 0) {
                        return true;
                    } else {
                        return false;
                    }
                },
                // 随机码
                randomWord: function (size) {
                    var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
                    var res = "";
                    for (var i = 0; i < size; i++) {
                        var id = Math.ceil(Math.random() * 35);
                        res += chars[id];
                    }
                    return res;
                },
                // 手机号码替换 134555554444 -> 134****4444
                phonenoReplace: function (phoneno, start, length, replaceFlg) {
                    start = start ? start : 3;
                    length = length ? length : 4;
                    replaceFlg = replaceFlg ? replaceFlg : "*";
                    var replaceStr = "";
                    for (var i = 0; i < length; i++) {
                        replaceStr = replaceStr + replaceFlg;
                    }
                    return phoneno ? phoneno.substr(0, start) + replaceStr + phoneno.substr(start + length) : replaceStr;
                },
                // 字符串是否以（startWith）开始
                isStrStartWith: function (str, startWith) {
                    if (!str || !startWith) return false;
                    var len = startWith.length;
                    return str.substr(0, len) == startWith;
                },
                //获得字符串的后几位
                getEndStr: function (str, len) {
                    return str ? str.substr(-1 * len) : "";
                },
                urlParam: function (param) {
                    return this.urlParamWithFixed(location.href, param);
                },
                // 链接中的参数params[可以为数组]
                urlParams: function (params) {
                    return this.urlParamsWithFixed(location.href, params);
                },
                urlParamWithFixed: function (url, param) {
                    if (!param) return "";
                    var pattern = new RegExp("[?&]" + param + "\=([^&]+)", "g");
                    var matcher = pattern.exec(url);
                    var res = "";
                    if (null !== matcher) {
                        try {
                            res = decodeURIComponent(decodeURIComponent(matcher[1]));
                        } catch (e) {
                            try {
                                res = decodeURIComponent(matcher[1]);
                            } catch (e) {
                                res = matcher[1];
                            }
                        }
                    }
                    if (res) {
                        res = res.indexOf("#") > 0 ? res.substr(0, res.indexOf("#")) : res;
                    }
                    return res;
                },
                // 链接中的参数
                urlParamsWithFixed: function (url, params) {
                    if (!params) return "";
                    var searchParmas;
                    if (params instanceof Array) {
                        searchParmas = params;
                    } else if (params instanceof String) {
                        searchParmas = [params];
                    } else {
                        return "";
                    }
                    var res = {};
                    for (var key in searchParmas) {
                        res[searchParmas[key]] = this.urlParamWithFixed(url, searchParmas[key]);
                    }
                    return res;
                },
                // 将对象转成url的参数信息
                toUrlParams: function (obj) {
                    if (!obj) return "";
                    var paramStr = "";
                    $.each(obj, function (i, item) {
                        if (item.value != undefined) {
                            if (paramStr) {
                                paramStr += "&" + item.key + "=" + item.value;
                            } else {
                                paramStr = item.key + "=" + item.value;
                            }
                        }
                    });
                    return paramStr;
                },
                // 是否有url参数
                hasUrlParams: function (url) {
                    return url ? url.indexOf("?") >= 0 : false;
                },
                // 日期间隔 目前只支持yyyy-MM-dd yyyy/MM/dd
                dateDiff: function (dateTime1, dateTime2) {
                    var beginTime = new Date(dateTime1.pattern("yyyy-MM-dd").replace(/-/g, "/"));
                    var endTime = new Date(dateTime2.pattern("yyyy-MM-dd").replace(/-/g, "/"));
                    var days = Math.abs((beginTime - endTime)) / (1000 * 60 * 60 * 24);
                    return days;
                },
                // 当前日期多少天以后的日期
                daysAfter: function (days) {
                    return this.daysAfterWithFixed(new Date(), days);
                },
                // 指定日期的多少天之后日期
                daysAfterWithFixed: function (startDate, days) {
                    var beginTime = new Date(fromTime.pattern("yyyy-MM-dd").replace(/-/g, "/"));
                    var addTime = days * 1000 * 60 * 60 * 24;
                    return new Date(beginTime + addTime);
                },
                // str -> 日期
                str2Date: function (str) {
                    try {
                        return new Date(str.replace(/-/g, "/"));
                    } catch (e) {
                        console.warn(e.message);
                        return null;
                    }
                },
                // 日期 -> str
                date2Str: function (date, formatString) {
                    return date.pattern(formatString);
                },
                json2Str: function (o) {
                    var arr = [];
                    var fmt = function (s) {
                        if (typeof s == 'object' && s != null) return json2str(s);
                        return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
                    }
                    for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
                    return '{' + arr.join(',') + '}';
                },

                str2Json: function (stringValue) {
                    eval("var theJsonValue = " + stringValue);
                    return theJsonValue;
                },
                // 金额格式化
                formatAmount: function (amount, intLen, floatLen) {
                    if (!amount) return "0.00";
                    intLen ? void(0) : intLen = 3;
                    floatLen == 0 ? void(0) : floatLen = 2;
                    amount = Math.round(parseFloat((amount + "").replace(/[^\d\.-]/g, "")) * 100) / 100;
                    amount = amount + "";
                    var intArr = amount.split(".")[0].split("").reverse(), fval = amount.split(".")[1], intStr = "";
                    for (i = 0; i < intArr.length; i++) {
                        intStr += intArr[i] + ((i + 1) % intLen == 0 && (i + 1) != intArr.length ? "," : "");
                    }
                    if (floatLen && floatLen != 0) {
                        if (fval) {
                            for (i = fval.length + 1; i <= floatLen; i++) {
                                fval += "0";
                            }
                            fval = "." + fval;
                        } else {
                            fval = ".00";
                        }
                    } else {
                        fval = "";
                    }
                    intStr = intStr.split("").reverse().join("");
                    intStr = intStr + fval;
                    return intStr;
                },
                // 投资金额输入框 只能输入数字
                validateNumberOnly: function (e, amount) {
                    if (!/^\d+$/.test(amount)) {
                        e.value = /^\d+/.exec(e.value);
                        if (e.value == "null") {
                            e.value = "";
                        }
                    }
                },
                //格式化金额
                getAmount: function (amount) {
                    var _this = this;
                    var unit = "";
                    if (amount >= 10000) {
                        amount = _this.formatAmount(amount / 10000, 3, 2).replace(".00", "");
                        unit = "万元";
                    } else {
                        amount = _this.formatAmount(amount, 3, 0);
                        unit = "元";
                    }
                    return [amount, unit];
                },
                //取消字符串中出现的所有逗号
                replaceCommaWithEmpty: function (amount) {
                    if (!amount) return "";
                    return amount.replace(/,/g, "");
                },
                // 跳转
                windowJump: function (url, isReplaceUrl) {
                    if (!url) url = "/";
                    if (isReplaceUrl) {
                        window.location.replace(url);
                    } else {
                        window.location.href = url;
                    }
                },
                windowJumpToStep: function (step) {
                    if (step) window.location.hash = step;
                },
                requestServerJump: function (url) {
                    if (!url) url = "/";
                    if (_Common_Config.isDebug) {
                        window.location.href = _Common_Config.host + url;
                    } else {
                        window.location.href = url;
                    }
                },
                // 阻止浏览器默认效果的触发
                pervent: function (e) {
                    if (e && e.stopPropagation) {
                        e.stopPropagation();
                    } else {
                        window.event.cancelBubble = true;
                    }
                    if (e && e.preventDefault) {
                        e.preventDefault();
                    }
                    else {
                        window.event.returnValue = false;
                    }
                    return false;
                },
                htmlencode: function (s) {
                    var div = document.createElement('div');
                    div.appendChild(document.createTextNode(s));
                    return div.innerHTML;
                },
                htmldecode: function (s) {
                    var div = document.createElement('div');
                    div.innerHTML = s;
                    return div.innerText || div.textContent;
                },
                // 微信分享
                withShare: function (option) {
                    var _this = this;
                    //默认设置
                    var share_def = {
                        pics: "https://www.jplicai.com/frontlib/img/icon/shareLogo2.png",
                        resMode: "window",
                        title: option.title,
                        summary: option.summary,
                        desc: option.desc,
                    };

                    //更新默认设置函数
                    var _upd_def = function (option) {
                        if (option) {
                            var tmp = {};
                            for (var k in option) {
                                if (typeof k !== 'object') {
                                    tmp[k] = option[k];
                                }
                            }
                            $.extend(share_def, tmp);
                        }
                    };

                    //更新默认设置
                    _upd_def(option || {});
                    $(".link-wx").hover(
                        function () {
                            shareDialog("weixin", _share_opt("weixin"));
                            $("#divImg").css("display", "block");
                        }, function () {
                            $("#divImg").css("display", "none");
                        }
                    );
                    $(".pro-icon-img").on("click", function () {
                        var command = $(this).attr("command");
                        if (command !== 'weixin') {
                            shareDialog(command, _share_opt(command));
                        }
                    });
                    var _share_opt = function (command) {
                        if (option && option.spec && option.spec[command]) {
                            var tmp = {};
                            $.extend(tmp, share_def);
                            tmp.pics = option.spec[command].pics || tmp.pics;
                            tmp.targetUrl = option.spec[command].targetUrl.call();
                            if (option.spec[command].summary) {
                                tmp.summary = option.spec[command].summary.call();
                            }
                            ;
                            if (option.spec[command].title) {
                                tmp.title = option.spec[command].title.call();
                            }
                            ;
                            if (option.spec[command].desc) {
                                tmp.desc = option.spec[command].desc.call();
                            }
                            ;
                            return tmp;
                        }
                        return share_def;
                    };
                },
                uniqueArr:function(arr) {
                   var tmp = new Array();
                    for ( var i in arr) {
                        if (tmp.indexOf(arr[i]) == -1) {
                            if(arr.hasOwnProperty(i)){
                                tmp.push(arr[i]);
                            }
                        }
                    }
                    return tmp;
                },
                sortVol:function(keyArr){
                    var patternSpec = /^(\d+(\.\d+)?)/gi;
                    var patternGrp = /(\d+)/g;
                    keyArr.sort(function(a,b){
                        var tmpAArr = a.match(patternGrp);
                        var tmpBArr = b.match(patternGrp);
                        if(tmpAArr.length == 1 && tmpBArr.length == 1){
                            var tmpA1 = tmpAArr[0];
                            var tmpB1 = tmpBArr[0];
                            return tmpA1 - tmpB1;
                        }else{
                            var tmpA2 = "1";
                            var tmpB2 = "0";
                            if(tmpAArr.length > 1){
                                tmpA2 = tmpAArr[1];
                            }
                            if(tmpBArr.length > 1){
                                tmpB2 = tmpBArr[1];
                            }
                            var tmpA1 = a.match(patternSpec)[0];
                            var tmpb1 = b.match(patternSpec)[0];
                            if( tmpA1 == tmpb1){
                                return tmpA2 - tmpB2;
                            }
                            else
                            {
                                return tmpA1 - tmpb1;
                            }
                        }
                    });
                    return keyArr;
                },
                sortArr:function (keyArr) {
                    var tmp1 = keyArr[0];
                    var pattern = /^(\d+(\.\d+)?)$/;
                    var patternSpec = /^(\d+(\.\d+)?)/gi;
                    var patternGrp = /(\d+)/g;
                    if(pattern.test(tmp1)){ //数字
                        keyArr.sort(function(a,b){
                            return a - b;
                        });
                    }else if(patternSpec.test(tmp1)){
                        keyArr.sort(function(a,b){
                            var tmpAArr = a.match(patternGrp);
                            var tmpBArr = b.match(patternGrp);
                            if(tmpAArr.length == 1 && tmpBArr.length == 1){
                                var tmpA1 = tmpAArr[0];
                                var tmpB1 = tmpBArr[0];
                                return tmpA1 - tmpB1;
                            }else{
                                var tmpA2 = "1";
                                var tmpB2 = "0";
                                if(tmpAArr.length > 1){
                                    tmpA2 = tmpAArr[1];
                                }
                                if(tmpBArr.length > 1){
                                    tmpB2 = tmpBArr[1];
                                }
                                var tmpA1 = a.match(patternSpec)[0];
                                var tmpb1 = b.match(patternSpec)[0];
                                if( tmpA1 == tmpb1){
                                    return tmpA2 - tmpB2;
                                }
                                else
                                {
                                    return tmpA1 - tmpb1;
                                }
                            }
                        });
                    }
                    else{
                        keyArr.sort();
                    }
                    return keyArr;
                }
            };
            return utils;
        },
        // ajax 应放在utils,由于特殊性单独放出
        ajax: function (option) {
            var _this = this;
            if (!$ in window || !option) return;
            if (!option.url || !$.trim(option.url)) {
                return;
            }
            var url = option.url;
            if (_Common_Config.isDebug) {
                url = _Common_Config.host + url;
            }
            option.loadingContainer = option.loadingContainer || $(".page-loading");
            if (option.loadingContainer) {
                option.loadingContainer.addClass("loading");
            }
            //预留接口,又来做token验证
            var CheckToken = function () {
                return true;
            };
            var DefBeforeSend = function () {
                    if (!CheckToken()) {
                        return false;
                    }
                    // 画面loading
                    //if(!option.noLoading)jptbport.pager.init().loading('show');
                    if (option.beforeSend) {
                        option.beforeSend.call(this);
                    }
                    return true;
                },
                params = {
                    url: url,
                    type: option.type ? option.type : "post",
                    beforeSend: DefBeforeSend,
                    loadingContainer: null
                };
            params.dataType = option.dataType ? option.dataType : 'json';
            if (option.data) params.data = option.data;
            if (option.async != undefined) params.async = option.async;
            var responseData;
            params.success = function (data, status, xhr) {
                responseData = data;
                if (option.success) {
                    option.success.call(this, responseData, status);
                } else {
                    return true;
                }
            },
               params.error = function (xhr, errorType, error) {
                    closeLoading();
                    // 自定义错误处理时,回调
                    if (option.error) {
                        var data = {
                            code: "error",
                            message: "",
                            status: xhr.status
                        };
                        option.error.call(this, data, errorType);
                        return;
                    }
                    // if (xhr.status == 400) {
                    //     _this.utils().windowJump("../error/400.html");
                    // } else if (xhr.status == 401) {
                    //     _this.utils().windowJump("../error/401.html");
                    // } else if (xhr.status == 404) {
                    //     _this.utils().windowJump("../error/404.html");
                    // } else if (xhr.status == 500) {
                    //     _this.utils().windowJump("../error/500.html");
                    // }
                },
                params.complete = function () {
                    closeLoading();
                    if (option.complete) option.complete.call(this, responseData);
                };

            function closeLoading() {
                if (option.loadingContainer) {
                    option.loadingContainer.removeClass("loading");
                }
            }

            try {
                $.ajax(params);
            } catch (e) {

            }

        }
    }
}


var SYS_CONFIG = {
    wxId: "",
    domain: "https://www.jinpiaotong.com",
    debug: true
};
window.lib || (window.lib = {});
window.lib["PcCommon"] = PcCommon;

/**
 * 日期扩展
 */
Date.prototype.pattern = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,
        //月份
        "d+": this.getDate(),
        //日
        "h+": this.getHours() % 12 === 0 ? 12 : this.getHours() % 12,
        //小时
        "H+": this.getHours(),
        //小时
        "m+": this.getMinutes(),
        //分
        "s+": this.getSeconds(),
        //秒
        "q+": Math.floor((this.getMonth() + 3) / 3),
        //季度
        "S": this.getMilliseconds() //毫秒
    };
    var week = {
        "0": "/u65e5",
        "1": "/u4e00",
        "2": "/u4e8c",
        "3": "/u4e09",
        "4": "/u56db",
        "5": "/u4e94",
        "6": "/u516d"
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    if (/(E+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};
String.prototype.format = function (args) {
    var result = this;
    if (arguments.length > 0) {
        if (arguments.length == 1 && typeof (args) == "object") {
            for (var key in args) {
                if (args[key] != undefined) {
                    var reg = new RegExp("({" + key + "})", "g");
                    result = result.replace(reg, args[key]);
                }
            }
        }
        else {
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] != undefined) {
                    //var reg = new RegExp("({[" + i + "]})", "g");//这个在索引大于9时会有问题，谢谢何以笙箫的指出
                    var reg = new RegExp("({)" + i + "(})", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
    }
    return result;
};


if ("function" == typeof define && define.amd && define) {
    define(['jquery', 'common/header','common/alertInfo'], function ($, header,alertInfo) {
        return PcCommon($, header,alertInfo);
    });
}
